<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>送修信息登记</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/layui/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/layui/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" method="post" id="applyForm">
    <div class="layui-form-item">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-block">
            <select id="carid" name="carid" lay-filter="carid">

            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">修理厂</label>
        <div class="layui-input-block">
            <select id="btypeid" name="btypeid">
                <option></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">送修时间</label>
        <div class="layui-input-block">
            <input type="text" id="repairstarttime" name="repairstarttime" autocomplete="off" required  lay-verify="required" placeholder="请输入送修时间" class="layui-input usetime">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">预计取车时间:</label>
        <div class="layui-input-block">
            <input type="text" id="repairplanendtime" name="repairplanendtime" autocomplete="off" required  lay-verify="required" placeholder="请输入送修时间" class="layui-input usetime">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">送修原因:</label>
        <div class="layui-input-block">
            <input type="text" id="repairreason" name="repairreason" required  lay-verify="required" placeholder="请输入送修原因" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">送修备注:</label>
        <div class="layui-input-block">
            <input type="text" id="remarkto" name="remarkto" required  lay-verify="required" placeholder="请输入送修备注" autocomplete="off" class="layui-input">
        </div>
      </div>

    <div class="layui-form-item">
        <label class="layui-form-label">经办人:</label>
        <div class="layui-input-block">
            <input type="text" id="drivername" required  lay-verify="required" autocomplete="off" class="layui-input" readonly="readonly">
        </div>
    </div>
            <input type="hidden" id="driverid" name="driverid"/>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="applyAdd" id="addBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>


</form>
<script type="text/javascript" src="<%=request.getContextPath()%>/static/layui/layui/layui.js"></script>
<script>
    layui.use(['form','layer','laydate','table','laytpl','upload'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table,
            upload=layui.upload;

        //绑定时间插件到文本框中
        $(".usetime").each(function () {
        laydate.render({
            elem:this,
            theme: 'grid',
            type: 'datetime'
            });
        });

        //提交表单
        form.on("submit(applyAdd)",function(data) {
            // var formData = new FormData($("#applyForm")[0]);
            $.ajax({
                url:"/repairRecord/repairRecordAdd",
                type: "post",
                data:$("#applyForm").serialize(),
                success:function (res) {
                    if(res.code == 1001){
                        layui.layer.msg(res.msg);
                    }else{
                        layui.layer.msg(res.msg);
                    }
                }
            });
            //点击提交后关闭悬浮窗
            setTimeout(function () {
                window.parent.location.reload();
            },1500);
            return false;
        });

        //动态显示车牌号码
        $.ajax({
            url: "/repairRecord/findAllCar",
            type:"post",
            success:function (data) {
                var message = "<option></option>";
                $.each(data,function (index,cars) {
                    message += "<option value="+cars.carid+">"+cars.carplate+"</option>";
                });
                $("#carid").html(message);
                form.render('select');
            }
        });

        //动态展示修理厂信息
        $.ajax({
            url:"/repairRecord/findAllBtype",
            type:"post",
            success:function (data) {
                var message = "<option></option>";
                $.each(data,function (index,btype) {
                    message += "<option value="+btype.btypeid+">"+btype.btypename+"</option>";
                });
                $("#btypeid").html(message);
                form.render('select');
            }
        });

        //动态显示修理级别
        $.ajax({
            url:"/repairRecord/findAllRepair",
            type:"post",
            success:function (data) {
                var message = "<option></option>";
                $.each(data,function (index,repair) {
                    message += "<option value="+repair.rid+">"+repair.rtype+"</option>";
                });
                $("#rid").html(message);
                form.render('select');
            }
        });

        form.on('select(carid)', function(data){
            $.ajax({
                url:"/car/car",
                type:"post",
                data:{"carid":data.value},
                success:function (res) {
                    $("#drivername").attr("value",res.data.driver.dirvername);
                    $("#driverid").attr("value",res.data.driver.driverid);
                }
            });
        })

        //批量删除
        $(".delAll_btn").click(function () {
            var checkStatus = table.checkStatus('userListTable');
            var data = checkStatus.data;
            var idArray = "";
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) {
                    idArray += data[i].petrolid + ",";
                }
            }
            $.ajax({
                url:"/petrolRecord/deleteIds",
                type:"post",
                data:{"idArray":idArray},
                success:function (data) {
                    if(data.code == 1001){
                        layui.layer.msg(data.msg);
                        tableIns.reload();
                    }else{
                        layui.layer.msg(data.msg);
                    }
                }
            });
        });



    })
</script>
</body>
</html>